<% layout('/layout/default.html', {title: '菜单管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-book-open"></i> 菜单管理
			</div>
			<div class="box-tools pull-right">
			
				<a href="#" class="btn btn-default" id="btnRefreshTree" title="刷新"><i class="fa fa-refresh"></i> 刷新</a>
				<a href="#" class="btn btn-default" id="btnExpandTreeNode" title="展开一级"><i class="fa fa-angle-double-down"></i> 展开</a>
				<a href="#" class="btn btn-default" id="btnCollapseTreeNode" title="折叠全部"><i class="fa fa-angle-double-up"></i> 折叠</a>
				<% if(hasPermi('sys:menu:edit')){ %>
					<a href="/sys/menu/form" class="btn btn-default btnTool"  title="新增菜单"><i class="fa fa-plus"></i> 新增</a>
					
					<a href="#" class="btn btn-default" id="btnUpdateSort" title="保存排序"><i class="fa fa-sort-amount-asc"></i> 保存排序</a>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<form id="searchForm" action="${ctx}/sys/menu/listData" method="post" class="form-inline hide" >
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">查询</button>
					<button type="reset" class="btn btn-default btn-sm">重置</button>
				</div>
			</form>		
			
			<form id="dataGridForm" action="${ctx}/sys/menu/updateSort" method="post" class="form-inline" >
				<table id="dataGrid"></table>
			</form>
		</div>
	</div>
</div>
<% } %>
<script>
//初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [ 
		{header:'菜单名称', name:'name', width:200, formatter: function(val, obj, row, act){
			return '<i class="'+row.icon+'"></i> <a href="/sys/menu/form?id='
					+row.id+'" class="btnList" data-title="编辑菜单">'+val+'</a>';
		}},
		{header:'链接', name:'href', width:150},
		{header:'排序', name:'sort', width:63, align:"center", formatter: function(val, obj, row, act){
			var html = [];
			<% if(hasPermi('sys:menu:edit')){ %>
			html.push('<input type="hidden" name="ids" value="'+row.id+'"/>');
			html.push('<input name="sorts" type="text" value="'+row.sort+'" style="width:50px;height:19px;margin:0;padding:0;text-align:center;border:1px solid #ddd">');
			<% }else{ %>
			html.push(row.sort);
			<% } %>
			return html.join('');
		}},
		{header:'可见', name:'isShow', width:50, fixed:true, align:"center", formatter: function(val, obj, row, act){
			return val=="1"?"显示":"隐藏";
		}},
		{header:'权限标识', name:'permission', width:150},
		{header:'操作', name:'actions', width:100, sortable:false, align:"center", formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('sys:menu:edit')){ %>
				actions.push('<a href="/sys/menu/form?id='+row.id+'" class="btnList" title="编辑菜单"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/sys/menu/delete?id='+row.id+'" class="btnList" title="删除菜单" data-confirm="确认要删除该菜单及所有子菜单吗？" data-deltreenode="'+row.id+'"><i class="fa fa-trash-o"></i></a>&nbsp;');
				actions.push('<a href="/sys/menu/form?parentId='+row.id+'" class="btnList" title="新增下级菜单"><i class="fa fa-plus-square"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	treeGrid: true,			// 启用树结构表格
	defaultExpandLevel: 0,
	expandNodeClearPostData: 'name',
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});



//绑定更新排序按钮
$('#btnUpdateSort').click(function(){
	 js.ajaxSubmitForm($("#dataGridForm"), function(data){
		if(data.result == "true"){
			$('#btnRefreshTree').click();
		}
		js.showMessage(data.message);
	});
});
</script>